package com.gzw.dms.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.gzw.dms.R;
import com.gzw.dms.bean.OrderNumberInfo;
import com.jauker.widget.BadgeView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gaozhiwei on 2015/10/10.
 */
public class MainGVAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> nameList;
    private List<OrderNumberInfo> lsMap;
    private BadgeView badgeView;
    public MainGVAdapter(Context _mContext, List<String> _nameList ,List<OrderNumberInfo> _lsMap) {
        mContext = _mContext;
        nameList = _nameList;
        lsMap = _lsMap;
    }

    @Override
    public int getCount() {
        return nameList.size();
    }

    @Override
    public Object getItem(int position) {

        return nameList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder = null;
        if (convertView == null) {
            convertView = View
                    .inflate(mContext, R.layout.item_gv_main, null);
            mHolder = new Holder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (Holder) convertView.getTag();
        }
      switch (nameList.get(position)){
          case "11":
              mHolder.iv.setImageResource(R.mipmap.zxwl);
              break;
          case "4":
              mHolder.iv.setImageResource(R.mipmap.nixiangwl);
              break;
          case "7":
              mHolder.iv.setImageResource(R.mipmap.user);
              break;
          case "8":
              mHolder.iv.setImageResource(R.mipmap.selfcenter);
              break;
          case "9":
              mHolder.iv.setImageResource(R.mipmap.message);
              if (lsMap.size()!=0 && lsMap!=null){
                  for (int i=0; i < lsMap.size();i++){
                  OrderNumberInfo orderNumberInfo = lsMap.get(i);
                  String type = orderNumberInfo.getType();
                  String type2 = orderNumberInfo.getNumber();
                  Integer number = Integer.parseInt(type2);
                  if (type.equals("orderMsgCount")) {
                      if (number != null) {
                          badgeView = new BadgeView(mContext);
                          badgeView.setTargetView(mHolder.iv);
                          badgeView.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
                          badgeView.setBadgeCount(number);
                          badgeView.setTextSize(18);
                      }
                  }
                  }
              }
              break;
          case "17":
              mHolder.iv.setImageResource(R.mipmap.qtjk);
              break;
      }
//        mHolder(ScreenUtils
//                .getScreenWidth(mContext) / 3);

        return convertView;
    }
    static class Holder {
        private TextView tvName;
        private ImageView iv;
        public Holder(View view) {
            iv=(ImageView)view.findViewById(R.id.iv);
        }
        public  ImageView getIv(){
            return iv;
        }
    }
}
